//
//  ViewController.m
//  MultiperThreadTest02
//
//  Created by FelixYin on 2020/4/4.
//  Copyright © 2020 FelixYin. All rights reserved.
//

#import "ViewController.h"
#import "OSSpinLockDemo.h"
#import "OSUnfairLockDemo.h"
#import "MutexLockDemo.h"
#import "MutexLock2Demo.h"
#import "NSLockDemo.h"
#import "NSConditionDemo.h"
#import "SerialQueueDemo.h"
#import "SeamphoreDemo.h"
#import "SynchronizedDemo.h"

@interface ViewController ()

@property (nonatomic,strong) OSSpinLockDemo *ossLockDemo;
@property (nonatomic,strong) OSUnfairLockDemo *osUnFairLockDemo;
@property (nonatomic,strong) MutexLockDemo *muteDemo;
@property (nonatomic,strong) MutexLock2Demo *muteDemo2;
@property (nonatomic,strong) NSLockDemo *nsLockDemo;
@property (nonatomic,strong) NSConditionDemo *nsconditionLock;
@property (nonatomic,strong) SerialQueueDemo *serialQueue;
@property (nonatomic,strong) SeamphoreDemo *seamphore;
@property (nonatomic,strong) SynchronizedDemo *synchronized;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self.ossLockDemo saveAndDrawMoney];
//    [self.osUnFairLockDemo saveAndDrawMoney];
//    [self.muteDemo saveAndDrawMoney];
//    [self.muteDemo test]; //测试死锁情况
//    [self.muteDemo test3]; //递归锁
//    [self.muteDemo2 test]; //锁条件 使用
//    [self.nsLockDemo saveAndDrawMoney];
//    [self.nsconditionLock test];
//    [self.serialQueue saveAndDrawMoney];
//    [self.serialQueue saleTickets];
//    [self.seamphore test];
//    [self.seamphore saveAndDrawMoney];
//    [self.seamphore saleTickets];
    [self.synchronized saveAndDrawMoney];
    [self.synchronized saleTickets];
}


// MARK: Lazy Loading

- (OSSpinLockDemo *)ossLockDemo{
    if (!_ossLockDemo) {
        _ossLockDemo = [[OSSpinLockDemo alloc] init];
    }
    return _ossLockDemo;
}

- (OSUnfairLockDemo *)osUnFairLockDemo{
    if (!_osUnFairLockDemo) {
        _osUnFairLockDemo = [[OSUnfairLockDemo alloc] init];
    }
    return _osUnFairLockDemo;
}

- (MutexLockDemo *)muteDemo{
    if (!_muteDemo) {
        _muteDemo = [[MutexLockDemo alloc] init];
    }
    return _muteDemo;;
}

- (MutexLock2Demo *)muteDemo2{
    if (!_muteDemo2) {
        _muteDemo2 = [[MutexLock2Demo alloc] init];
    }
    return _muteDemo2;;
}

- (NSLockDemo *)nsLockDemo{
    if (!_nsLockDemo) {
        _nsLockDemo = [[NSLockDemo alloc] init];
    }
    return _nsLockDemo;
}

- (NSConditionDemo *)nsconditionLock{
    if (!_nsconditionLock) {
        _nsconditionLock = [[NSConditionDemo alloc] init];
    }
    return _nsconditionLock;;
}

- (SerialQueueDemo *)serialQueue{
    if (!_serialQueue) {
        _serialQueue = [[SerialQueueDemo alloc] init];
    }
    return _serialQueue;;
}

- (SeamphoreDemo *)seamphore{
    if (!_seamphore) {
        _seamphore = [[SeamphoreDemo alloc] init];
    }
    return _seamphore;;
}

- (SynchronizedDemo *)synchronized{
    if (!_synchronized) {
        _synchronized = [[SynchronizedDemo alloc] init];
    }
    return _synchronized;;
}


@end
